/**
 * PackageDir: info.javafans.cdn.dao
 * FileName: GroupDao.java
 * CreateDate: 2011-3-6 上午08:30:00
 * Copyright: Copyright (c) 2011 <br />
 * Company: fossd <br />
 * @author Yintao Xue
 * @version 1.0 2011-3-6
 */
package info.javafans.cdn.dao;

import info.javafans.cdn.database.DbHelper;
import info.javafans.cdn.domain.Group;

import java.util.List;

import org.apache.log4j.Logger;

/**
 * Project: CollegeDatingNetwork <br />
 * ClassName: GroupDao <br />
 * Description: <br />
 */
public class GroupDao {

	public static Logger logger = Logger.getLogger(GroupDao.class);

	/**
	 * 获取活跃社团 selectActiveGroup
	 * 
	 * @return
	 */
	public static List<Group> selectActiveGroup() {
		String sql = "select * from groups order by score desc limit 0,5";
		List<Group> groupList = null;
		groupList = DbHelper.queryBeanList(Group.class, sql, null);

		// 设置每个社团的类型
		for (Group g : groupList) {
			g.setGroupType(GroupTypeDao.selectGroupTypeById(g.getGroupTypeId()));
		}

		return groupList;
	}
	
	/**
	 * 按id查询group
	 * selectGroupById
	 * @param id
	 * @return
	 */
	public static Group selectGroupById(int id) {
		String sql = "select * from groups where id = ?";
		Group group = DbHelper.queryBean(Group.class, sql, id);
		return group;
	}
	
	/**
	 * 获得社团列表
	 * selectGroupList
	 * @return
	 */
	public static List<Group> selectGroupList() {
		String sql = "select * from groups";
		List<Group> groupList = DbHelper.queryBeanList(Group.class, sql, null);
		// 设置每个社团的类型
		for (Group g : groupList) {
			g.setGroupType(GroupTypeDao.selectGroupTypeById(g.getGroupTypeId()));
		}
		return groupList;
	}
}
